package code;

public class Code {
	
	/**
	 * The arguments a Code can have
	 */
	private double[] args;
	
	/**
	 * The Opcode of the Code
	 */
	private Opcode opcode;
	
	/**
	 * Constructor
	 * @param opcode
	 * @param args
	 */
	public Code(Opcode opcode, double ... args) {
		this.opcode = opcode;
		this.args = args;
	}
	
	/**
	 * Getter
	 * @return {@link #opcode}
	 */
	public Opcode getOpcode() {
		return this.opcode;
	}
	
	/**
	 * Getter
	 * @return {@link #args}
	 */
	public double[] getArgs() {
		return args;
	}
 		
	/**
	 * Setter, sets the Arguments-Array to args
	 * @param args
	 */
	public void setArgs(double[] args) {
		this.args = args;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		String result = "";
		result += getOpcode().name() + " ";
		for (double d : getArgs()) {
			if (getOpcode().needsInteger()) {
				result += ((int) d) + " ";
			}
			else {
				result += d + " ";
			}
		}
		result += "\n";
		return result;
	}
	
}
